package com.jojo.android.zxlib.view;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.bumptech.glide.Glide;
import com.jojo.android.zxlib.R;
import com.jojo.android.zxlib.base.BaseActivity;
import com.jojo.android.zxlib.base.mvp.BasePresenter;

import butterknife.BindView;


/**
 * 创建者 zx
 * 创建时间 2020/9/11 14:11
 */
public class PhotoActivity extends BaseActivity implements DragClosePhotoView.OnExitListener, DragClosePhotoView.OnTapListener, View.OnClickListener {
    private final String TAG = "PhotoActivity";

    private String imagePath;
    private int resId = -1;

    DragClosePhotoView photoView;

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_photo;
    }

    @Override
    public void setStatusBarLightMode(boolean lightMode) {
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }

    @Override
    protected boolean isImmerse() {
        return true;
    }

    @Override
    protected void initUI() {
        photoView = findViewById(R.id.photoView);
        Intent intent = getIntent();
        if (intent != null) {
            imagePath = intent.getStringExtra("image");
            resId = intent.getIntExtra("resId", -1);
        }
        if (!TextUtils.isEmpty(imagePath)) {
            Glide.with(this).load(imagePath).into(photoView);
        } else if (resId != -1) {
            Glide.with(this).load(resId).into(photoView);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void regEvent() {
        photoView.setOnExitListener(this);
        photoView.setOnTapListener(this);
        photoView.setOnClickListener(this);
    }

    @Override
    public void onBackPressed() {
        finish();
        overridePendingTransition(0, R.anim.hold);
    }


    @Override
    public void onExit(DragClosePhotoView view, float translateX, float translateY, float w, float h, float scale) {
        finish();
        overridePendingTransition(0, R.anim.anim_bottom_out);
    }

    @Override
    public void onTap(DragClosePhotoView view) {

    }

    @Override
    public void onClick(View v) {
        onBackPressed();
    }
}
